<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Package_no')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-package_no" data-rule="required" class="form-control"    disabled="disabled"  value="{$row.package_no|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('User_id')} ID:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-user_id" data-rule="required" class="form-control"  disabled="disabled" type="number" value="{$row.user_id|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input id="c-image" class="form-control" size="50" name="row[image]" type="text" value="{$row.image|htmlentities}">
                <div class="input-group-addon no-border no-padding">
                    <span><button type="button" id="faupload-image" class="btn btn-danger faupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
                    <span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
                </div>
                <span class="msg-box n-right" for="c-image"></span>
            </div>
            <ul class="row list-inline faupload-preview" id="p-image"></ul>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('包裹重量')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-delivery_weight"   class="form-control"  name="row[delivery_weight]" type="number" value="{$row.delivery_weight|htmlentities}">
        </div>
    </div>

    <?php if($row['state']==6): ?>
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">{:__('Express_no')}:</label>
            <div class="col-xs-12 col-sm-8">
                <input id="c-express_no"   class="form-control"  name="row[express_no]"   value="{$row.express_no|htmlentities}">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">{:__('Express_name')}:</label>
            <div class="col-xs-12 col-sm-8">
                <input id="c-express_name"   class="form-control"  name="row[express_name]"   value="{$row.express_name|htmlentities}">
            </div>
        </div>
    <?php endif;  ?>

    <?php if($row['state']==6): ?>
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">{:__('Delivery_price')}:</label>
            <div class="col-xs-12 col-sm-8">
                <input id="c-delivery_price"   class="form-control"  name="row[delivery_price]" type="number" value="{$row.delivery_price|htmlentities}">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
            <div class="col-xs-12 col-sm-8">

                <div class="radio">
                    {foreach name="statusList" item="vo"}
                    <label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="$row.status"}checked{/in} /> {$vo}</label>
                    {/foreach}
                </div>

            </div>
        </div>
    <?php endif; ?>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('箱数')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-box_num"   class="form-control"  name="row[box_num]" type="number" value="{$row.box_num|htmlentities}">
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Remark')}:</label>
        <div class="col-xs-12 col-sm-8">
            <textarea  id="c-remark"   class="form-control"  name="row[remark]" >{$row.remark|htmlentities}</textarea>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Consignor')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-consignor"   class="form-control"  name="row[consignor]"   value="{$row.consignor|htmlentities}">
        </div>
    </div>

    <div class="form-group" style="height: 30px;background: #0a6aa1;color:white;text-align: center;line-height: 30px;margin: 10px;">商品</div>
    <?php if($row['state']==1): ?>
        <div class="form-group"  id="goods-add" style="border-radius:5px;height: 30px;width:70px;background: #a3bce4;color:white;text-align: center;line-height: 30px;margin: 10px;">追加商品</div>
    <?php endif; ?>
    <div id="goods-div" style="border-top: #0a6aa1 solid 1px;border-bottom: #0a6aa1 solid 1px;">
        <?php if($goods): ?>
            <?php foreach($goods as $k=>$val): ?>
                <?php if($k==0): ?>
                    <div style="margin-top: 5px;padding-top: 5px;" class="goods_info" >
                <?php else: ?>
                    <div style="border-top: #a3bce4 1px solid;margin-top: 5px;padding-top: 10px;" class="goods_info">
                <?php endif; ?>
                <?php if($row['state']==1): ?>
                        <div class="form-group">
                            <label class="control-label col-xs-12 col-sm-2">{:__('商品名称')}:</label>
                            <div class="col-xs-12 col-sm-8">
                                <input id="c-old_name<?=$k;?>"  data-rule="required"  class="form-control" name="old_goods[<?=$val['id'];?>][name]" type="text" value="<?=$val['name'];?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-xs-12 col-sm-2">{:__('商品数量')}:</label>
                            <div class="col-xs-12 col-sm-8">
                                <input id="c-old_number<?=$k;?>"  data-rule="required" step="1" class="form-control" name="old_goods[<?=$val['id'];?>][number]" type="number" value="<?=$val['number'];?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-xs-12 col-sm-2">{:__('商品价格')}:</label>
                            <div class="col-xs-12 col-sm-8">
                                <input id="c-old_price<?=$k;?>"  data-rule="required" step="0.01" class="form-control" name="old_goods[<?=$val['id'];?>][price]" type="number" value="<?=$val['price'];?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-xs-12 col-sm-2">{:__('重量')}:</label>
                            <div class="col-xs-12 col-sm-8">
                                <input id="c-old_weight<?=$k;?>"   data-rule="required" step="0.01"  class="form-control" name="old_goods[<?=$val['id'];?>][weight]" type="number" value="<?=$val['weight'];?>">
                            </div>
                        </div>
                <?php else: ?>
                        <div class="form-group">
                            <label class="control-label col-xs-12 col-sm-2">{:__('商品名称')}:</label>
                            <div class="col-xs-12 col-sm-8">
                                <input   data-rule="required" disabled="disabled"  class="form-control"  type="text" value="<?=$val['name'];?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-xs-12 col-sm-2">{:__('商品数量')}:</label>
                            <div class="col-xs-12 col-sm-8">
                                <input disabled="disabled"  data-rule="required" step="1" class="form-control"  type="number" value="<?=$val['number'];?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-xs-12 col-sm-2">{:__('商品价格')}:</label>
                            <div class="col-xs-12 col-sm-8">
                                <input  disabled="disabled"  data-rule="required" step="0.01" class="form-control"   type="number" value="<?=$val['price'];?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-xs-12 col-sm-2">{:__('重量')}:</label>
                            <div class="col-xs-12 col-sm-8">
                                <input  disabled="disabled"   data-rule="required" step="0.01"  class="form-control"   type="number" value="<?=$val['weight'];?>">
                            </div>
                        </div>
                <?php endif; ?>

                    <?php if($k>0 && $row['state']==1): ?>
                        <div class="form-group"  onclick="del(this)" style="border-radius:5px;height: 30px;width:70px;background: #a2a2a2;color:white;text-align: center;line-height: 30px;margin: 10px;">删除</div>
                    <?php endif; ?>
                </div>
            <?php endforeach; ?>
        <?php else: ?>
        <div style="margin-top: 5px;padding-top: 5px;" class="goods_info" >
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('商品名称')}:</label>
                <div class="col-xs-12 col-sm-8">
                    <input id="c-name0"  data-rule="required"  class="form-control" name="goods[name][]" type="text" value="">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('商品数量')}:</label>
                <div class="col-xs-12 col-sm-8">
                    <input id="c-number0"  data-rule="required" step="1" class="form-control" name="goods[number][]" type="number" value="">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('商品价格')}:</label>
                <div class="col-xs-12 col-sm-8">
                    <input id="c-price0"  data-rule="required" step="0.01" class="form-control" name="goods[price][]" type="number" value="">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('重量')}:</label>
                <div class="col-xs-12 col-sm-8">
                    <input id="c-weight0"   data-rule="required" step="0.01"  class="form-control" name="goods[weight][]" type="number" value="">
                </div>
            </div>
        </div>
        <?php endif; ?>

    </div>

    <div class="form-group" style="height: 30px;background: #0a6aa1;color:white;text-align: center;line-height: 30px;margin: 10px;">收货地址</div>
    <?php if($row['state']==1): ?>
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">{:__('收货人名称')}:</label>
            <div class="col-xs-12 col-sm-8">
                <input   data-rule="required"  class="form-control" name="address[name]" type="text" value="<?=$address['name'];?>">
                <input type="hidden" name="address[id]" type="text" value="<?=$address['id'];?>">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">{:__('收货人手机号')}:</label>
            <div class="col-xs-12 col-sm-8">
                <input   data-rule="required"  class="form-control" name="address[mobile]" type="text" value="<?=$address['mobile'];?>">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">{:__('省/市/区')}:</label>
            <div class="col-xs-12 col-sm-8">
                <div class='control-relative'><input id="c-city" class="form-control" data-toggle="city-picker" name="address[city]" type="text" value="<?=$address['city'];?>"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">{:__('收货人具体地址')}:</label>
            <div class="col-xs-12 col-sm-8">
                <textarea   data-rule="required"  class="form-control" name="address[address]"><?=$address['address'];?></textarea>
            </div>
        </div>
    <?php else: ?>
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">{:__('收货人名称')}:</label>
            <div class="col-xs-12 col-sm-8">
                <input   data-rule="required"  class="form-control" disabled="disabled"   type="text" value="<?=$address['name'];?>">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">{:__('收货人手机号')}:</label>
            <div class="col-xs-12 col-sm-8">
                <input   data-rule="required"  disabled="disabled" class="form-control"   type="text" value="<?=$address['mobile'];?>">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">{:__('省/市/区')}:</label>
            <div class="col-xs-12 col-sm-8">
                <div class='control-relative'>
                    <input   class="form-control" disabled="disabled" data-toggle="city-picker"  type="text" value="<?=$address['city'];?>">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">{:__('收货人具体地址')}:</label>
            <div class="col-xs-12 col-sm-8">
                <textarea   data-rule="required" disabled="disabled"  class="form-control" ><?=$address['address'];?></textarea>
            </div>
        </div>
    <?php endif; ?>

    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
        </div>
    </div>
</form>

<script src="/assets/libs/jquery/dist/jquery.js"></script>
<script>
    var goods_html = `
    <div style="border-top: #a3bce4 1px solid;margin-top: 5px;padding-top: 10px;" class="goods_info">
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('商品名称')}:</label>
                <div class="col-xs-12 col-sm-8">
                    <input id="c-name##"   data-rule="required"  class="form-control" name="goods[name][]" type="text" value="">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('商品数量')}:</label>
                <div class="col-xs-12 col-sm-8">
                    <input  id="c-number##" data-rule="required" step="1" class="form-control" name="goods[number][]" type="number" value="">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('商品价格')}:</label>
                <div class="col-xs-12 col-sm-8">
                    <input id="c-price##"  data-rule="required" step="0.01" class="form-control" name="goods[price][]" type="number" value="">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('重量')}:</label>
                <div class="col-xs-12 col-sm-8">
                    <input  id="c-weight##" data-rule="required" step="0.01"  class="form-control" name="goods[weight][]" type="number" value="">
                </div>
            </div>
            <div class="form-group"  onclick="del(this)" style="border-radius:5px;height: 30px;width:70px;background: #a2a2a2;color:white;text-align: center;line-height: 30px;margin: 10px;">删除</div>
        </div>
    `;
   $("#goods-add").click(function () {
       var num = $(".goods_info").length
       console.log(num);
       var new_goods_html = goods_html.replace(/##/g,num);
        $("#goods-div").append(new_goods_html)
   });
   function del(ob) {
        $(ob).parent().remove();
   }

</script>
